home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / P4⁄Mac 2.0d4 / Mac source 2.0 / Run.p < prev    next >
Encoding:
Text File  |  1996-09-28  |  2.7 KB  |  120 lines  |  [TEXT/PJMM]

  1. {P4/Mac port by Ingemar Ragenamlm 1994-1996}
  2.  
  3. unit Run;
  4.  
  5. interface
  6.     uses
  7. {$IFC UNDEFINED THINK_PASCAL}
  8.         Types, QuickDraw, Windows, Dialogs, ToolUtils, Events, Controls, {}
  9.         Memory, Sound, OSUtils, MixedMode, 
  10. {$ENDC}
  11.         TransEdit, TransSkel, EditWindow, pascalcompiler, pcode, Messages;
  12.  
  13.     procedure Run;
  14.     procedure Compile;
  15.     procedure RunPcode;
  16.  
  17. implementation
  18.  
  19.     procedure DoRun (runFlag: Boolean);
  20.         var
  21.             fileInfo: SFReply;
  22.             newFile: Str255;
  23.             saved: Boolean;
  24.         function CommandPeriod: Boolean;
  25.             var
  26.                 km: KeyMap;
  27.         begin
  28.             CommandPeriod := false;
  29.             GetKeys(km);
  30.             if km[47] and km[55] then
  31.                 CommandPeriod := true;
  32.         end; {CommandPeriod}
  33.     begin
  34. {Hämta främsta editfönstrets text}
  35. {Kör det i compiler}
  36. {Fel skall skrivas i ett error-fönster.}
  37. {Resultatet skall sparas i MINNET och skickas}
  38. {direkt till run!}
  39. {}
  40. {Ett körfönster öppnas och skall HELST köras}
  41. {som kooperativ thread }
  42.  
  43.         if FrontWindow <> nil then
  44.             begin
  45.                 saved := EWindowSave(FrontWindow);
  46.                 if GetEWindowFile(FrontWindow, @fileInfo) then
  47.                     begin
  48.                         HideWindow(messagesWind);
  49.  
  50.                         if SetVol(nil, fileInfo.vRefNum) <> noErr then
  51.                             ; {We ignore errors for now}
  52.  
  53. {Is the open window pcode?}
  54.                         if Length(fileInfo.fName) > Length('.pcode') then
  55.                             if Copy(fileInfo.fName, Length(fileInfo.fName) - Length('.pcode') + 1, Length('.pcode')) = '.pcode' then
  56.                                 begin
  57.                                     if runFlag then
  58.                                         RunInterpreter(fileInfo.fName);
  59.                                     Exit(DoRun);
  60.                                 end;
  61.  
  62.                         newFile := RunCompiler(fileInfo.fName);
  63.                         if runFlag then
  64.                             if newFile <> '' then
  65.                                 if not CommandPeriod then
  66. {Kan man inte stoppa om det blev kompileringsfel?}
  67.                                     RunInterpreter(newFile);
  68.                         Exit(DoRun);
  69.                     end;
  70.             end;
  71.  
  72. {If we get here, then the open window was not usable. Run compiler with no file name.}
  73. {That will cause it to prompt for a file.}
  74.         newFile := RunCompiler('');
  75.         if runFlag then
  76.             if newFile <> '' then
  77.                 RunInterpreter(newFile);
  78.     end; {DoRun}
  79.  
  80.  
  81.     procedure Run;
  82.     begin
  83.         DoRun(true);
  84.     end; {Run}
  85.  
  86.     procedure Compile;
  87.     begin
  88.         DoRun(false);
  89.     end; {Compile}
  90.  
  91.     procedure RunPcode;
  92.         var
  93.             fileInfo: SFReply;
  94.             newFile: Str255;
  95.     begin
  96.  
  97.         if FrontWindow <> nil then
  98.             begin
  99.                 if GetEWindowFile(FrontWindow, @fileInfo) then
  100.                     begin
  101.                         HideWindow(messagesWind);
  102.  
  103.                         if SetVol(nil, fileInfo.vRefNum) <> noErr then
  104.                             ; {We ignore errors for now}
  105.  
  106.                         newFile := fileInfo.fName;
  107.                         if Length(fileInfo.fName) > Length('.p') then
  108.                             if Copy(fileInfo.fName, Length(fileInfo.fName) - Length('.p') + 1, Length('.p')) = '.p' then
  109.                                 begin
  110.                                     newFile := ConCat(Copy(fileInfo.fName, 1, Length(fileInfo.fName) - 2), '.pcode');
  111.                                 end;
  112.  
  113.                         if newFile <> '' then
  114.                             RunInterpreter(newFile);
  115.                     end;
  116.             end;
  117.  
  118.     end; {RunPcode}
  119.  
  120. end.